<?php

namespace app\admin\model;

use think\Model;


class TaskSettle extends Model
{
    // 表名
    protected $table = 'task_settle';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'createtime_text',
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function return()
    {
        return $this->hasOne(ReturnType::class,'id','return_id');
    }

    public static function getSettle($task_id)
    {
        return self::with('return')->where('task_id',$task_id)->find();
    }
}
